package com.okwanshiwu.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public abstract class UuidUtil {

	/**
	 * 随机的32位uuid
	 * @return  60e71875a5374bf1a25ac41bfce21d70
	 */
	public static String get32UUID() {
		String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
		return uuid;
	}

	/**
	 *
	 * @param cluster
	 * @param len
	 * @return
	 */
	public static String getUUID(int cluster,int len){
		//int machinedId = 1; //集群个数
		int hashCode = UUID.randomUUID().toString().hashCode();
		if(hashCode < 0){
			hashCode = -hashCode;
		}
		return cluster + String.format("%0"+len+"d", hashCode);
	}
	
	public static String getOrderNo(int cluster){
		int hashCode = UUID.randomUUID().toString().hashCode();
		System.out.println(hashCode);
		if(hashCode < 0){
			hashCode = -hashCode;
		}
		return cluster + String.format("%015d", hashCode);
	}

	public static String getbatch_no(int cluster){
		//int machinedId = 1; //集群个数
		int hashCode = UUID.randomUUID().toString().hashCode();
		if(hashCode < 0){
			hashCode = -hashCode;
		}
		String dataString = new SimpleDateFormat("yyyyMMdd").format(new Date());
		return dataString + cluster + String.format("%08d", hashCode);
	}
	
	public static String getOrderNo(String numberId){
	    String sdf = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
	    return numberId.concat(sdf);
	}
	
	
	public static void main(String[] args) {
		System.out.println(get32UUID());
		System.out.println(getOrderNo(1));
		System.out.println(getbatch_no(1));
		System.out.println(getUUID(1,10));;
	}
}

